package com.alpha.tests;

import static org.junit.Assert.*;
import java.util.ArrayList;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.alpha.bom.Exam;
import com.alpha.bom.ExamResponse;
import com.alpha.bom.RealExam;
import com.alpha.bom.Student;

public class StudentTest {

	private Student student;
	private ExamResponse er1;
	private ExamResponse er2;
	private Exam e1;
	private Exam e2;
	
	@Before
	public void setUp() throws Exception {
		this.student = new Student(0);
		this.e1 = new RealExam(1);
		this.e2 = new RealExam(2);
		this.er1 = new ExamResponse(this.e1, this.student);
		this.er2 = new ExamResponse(this.e2, this.student);
		ArrayList<ExamResponse> examResponses = new ArrayList<ExamResponse>();
		examResponses.add(this.er1);
		this.student.setExamResponses(examResponses);
	}

	@After
	public void tearDown() throws Exception {
		this.student = null;
	}

	@Test
	public void testSearchExamResponseExamResponse() {
		ExamResponse erSearch1 = this.student.searchExamResponse(this.er1);
		ExamResponse erSearch2 = this.student.searchExamResponse(this.er2);
		assertSame(this.er1, erSearch1);
		assertSame(null, erSearch2);
	}

	@Test
	public void testSearchExamResponseInt() {
		ExamResponse erSearch1 = this.student.searchExamResponse(1);
		ExamResponse erSearch2 = this.student.searchExamResponse(2);
		assertSame(this.er1,erSearch1);
		assertSame(null, erSearch2);
	}

	@Test
	public void testSearchExamResponseExam() {
		ExamResponse erSearch1 = this.student.searchExamResponse(this.e1);
		ExamResponse erSearch2 = this.student.searchExamResponse(this.e2);
		assertSame(this.er1,erSearch1);
		assertSame(null, erSearch2);
	}

	@Test
	public void testAddExamResponse() {
		assertEquals(false,this.student.addExamResponse(this.er1));
		assertEquals(true,this.student.addExamResponse(this.er2));
	}

}
